package com.tangdi.Action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.tangdi.Utils;
import com.tangdi.Bean.CZGZ_GZLB;
import com.tangdi.Bean.CZGZ_SJGZ;
import com.tangdi.Bean.CZGZ_ZGGZMX;
import com.tangdi.Bean.XM_BM_XM_MC;
import com.tangdi.Dao.impl.GongziDWImpl;
import com.tangdi.Dao.impl.GongziMXImpl;

public class searchPersonGZAction  extends HttpServlet{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Logger logger = Logger.getLogger(searchPersonGZAction.class);
	public searchPersonGZAction() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
	}
	
	public void init() throws ServletException {
		// Put your code here
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request,response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
		
		String person_Name =request.getParameter("person_Name");
		String person_Bank =request.getParameter("person_Bank");
		String person_Idno =request.getParameter("person_Idno");
		String year_month =request.getParameter("year_month");
		 logger.info("person_Name:"+ person_Name +
							 "person_Bank:"+ person_Bank +
							 "person_Idno:"+ person_Idno +
							 "year_month:"+ year_month);
		 
		List<CZGZ_ZGGZMX> person_gzmx=new ArrayList<CZGZ_ZGGZMX>();
		GongziDWImpl gzmx = new GongziDWImpl();
		person_gzmx = gzmx.findListGZMX(year_month,person_Name,person_Bank,person_Idno);	
		
		//工资类别list
		List<CZGZ_GZLB> listlb=new ArrayList<CZGZ_GZLB>();
		GongziMXImpl gzlb = new GongziMXImpl();
		listlb = gzlb.listGZLBReport(year_month);
		
		//实际工资科目 按工资类别
		List<CZGZ_SJGZ> list_sjgz=new ArrayList<CZGZ_SJGZ>();
		GongziMXImpl sjgz = new GongziMXImpl();
		list_sjgz = sjgz.listSJGZReport(year_month);	
		
		//工资类别，科目项信息，组装
		Map<String,List<XM_BM_XM_MC>> map_bm_mc_list = new HashMap<String,List<XM_BM_XM_MC>>();
		for(int i=0;i<listlb.size();i++){
			List<XM_BM_XM_MC> bm_mc_list = new ArrayList<XM_BM_XM_MC>();
			logger.info(listlb.get(i).getLB_BM().trim());
			for(int j=0; j<list_sjgz.size(); j++){
				XM_BM_XM_MC bm_mc= new XM_BM_XM_MC();
				if((listlb.get(i).getLB_BM().trim()).equals(list_sjgz.get(j).getGZ_LB().trim())){					
					bm_mc.setXM_BM(Utils.getXM_BM(list_sjgz.get(j).getXM_BM().trim()));					
					bm_mc.setXM_MC(list_sjgz.get(j).getXM_MC().trim());					
					System.out.print(Utils.getXM_BM(list_sjgz.get(j).getXM_BM().trim()) + " | ");	
					bm_mc_list.add(bm_mc);
				}
			}
			map_bm_mc_list.put(listlb.get(i).getLB_BM().trim(), bm_mc_list);
		}
		HttpSession session=request.getSession();
		session.setAttribute("map_bm_mc_list",map_bm_mc_list);
		session.setAttribute("person_GZMX_List",person_gzmx);
		session.setAttribute("person_Name",person_Name);
		session.setAttribute("person_Bank",person_Bank);
		session.setAttribute("person_Idno",person_Idno);
		session.setAttribute("year_month",year_month);
		
		response.sendRedirect("searchPersonGZ.jsp");
		
	}	
}
